package com.zhouyer.study.servlet;

import com.zhouyer.study.server.Request;
import com.zhouyer.study.server.Response;

import java.util.Objects;

/**
 * HttpServlet,提供一个统一的Servlet处理抽象类，供具体的Servlet继承使用
 *
 * @author zhouyao
 * @version 1.0
 * @date 2021/9/14 2:23 下午
 */
public abstract class HttpServlet implements Servlet {
    /**
     * GET请求方式
     */
    private static final String REQUEST_METHOD_GET = "GET";
    /**
     * POST请求方式
     */
    private static final String REQUEST_METHOD_POST = "POSt";

    public abstract void doGet(Request request, Response response);

    public abstract void doPost(Request request, Response response);

    @Override
    public void service(Request request, Response response) throws Exception {
        if (Objects.equals(REQUEST_METHOD_GET, request.getMethod())) {
            doGet(request, response);
        } else {
            doPost(request, response);
        }
    }
}
